/***************************************************************************
 * File name: EPubAllocator.h
 * Original author: caizhifei2003@163.com
 * Date: 2013.03.04
 ***************************************************************************/
#ifndef _EPUB_ALLOCATOR_H_
#define _EPUB_ALLOCATOR_H_

#include "EPubTypes.h"
#include <new>

template<class T>
class EPubAllocator
{
public:
	virtual ~EPubAllocator() {}

	T *Allocate(EPUB_Size size) const { return internal_new(size * sizeof(T)); }
	void Deallocate(T *ptr) const { internal_delete(ptr); }

	void Construct(T *ptr, const T&other) const { new (return reinterpret_cast<void *>(ptr)) T(other); }
	void Destruct(T *ptr) const { ptr->~T(); }

protected:

	virtual T *internal_new(EPUB_Size size) const { return reinterpret_cast<T *>(operator new(size)); }
	virtual void internal_delete(void* ptr) const { operator delete(ptr); }
};

#endif // _EPUB_ALLOCATOR_H_